package com.lovo.util;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author cwl
 * @date 2020/10/19 22:04
 * @description  mybatis工具包
 */
public class MyBatisUtil {

    private  static SqlSessionFactory sqlSessionFactory;
    static {
        try {
            String resources = "mybatis.xml";
            InputStream resourceAsStream = Resources.getResourceAsStream(resources);
            sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);

        } catch (IOException e) {
            e.printStackTrace();
        }

    }
    public static SqlSession getSqlSession(){
        return sqlSessionFactory.openSession();
    }

}